package com.wh1200.mybatis.xmlless.util

import com.wh1200.mybatis.xmlless.AnnotationSupport
import com.wh1200.mybatis.xmlless.constant.Annotations
import java.lang.reflect.AnnotatedElement

/**
 * Created by 吴昊 on 2023/12/8.
 */
object FieldUtil {

  fun isInsertIgnore(element: AnnotatedElement): Boolean {
    return isTransient(element)
        || AnnotationSupport.isInsertIgnore(element)
        || element.hasAnyAnnotation(*AnnotationSupport.INSERT_IGNORE_ANNOTATIONS)
  }

  fun isUpdateIgnore(element: AnnotatedElement): Boolean {
    return isTransient(element)
        || AnnotationSupport.isUpdateIgnore(element)
        || element.hasAnyAnnotation(*AnnotationSupport.UPDATE_IGNORE_ANNOTATIONS)
  }

  fun isSelectIgnore(element: AnnotatedElement): Boolean {
    return isTransient(element)
        || element.hasAnnotation(Annotations.COUNT)
  }

  private fun isTransient(element: AnnotatedElement): Boolean {
    return AnnotationSupport.isTransient(element)
  }

}
